package com.jsle.common;

import java.util.Collections;
import java.util.Map;

import javax.annotation.Resource;

import com.jsle.common.dao.mybatis.BaseDao;
import com.jsle.financial.vo.Page;
import com.jsle.financial.vo.Result;

public class BaseService implements Service {

    @Resource
    private Manager baseManager;

    @Resource
    private BaseDao baseDao;

    public Result save(Object object) {
	return baseManager.save(object);
    }

    public <T> T selectOne(T obj) {
	return (T) baseDao.queryCountForObject(
obj.getClass().getSimpleName()
	        + ".selectOne", obj);
    }

    public Page queryByConditions(Class clazz, int pageNo, int pageSize,
	    Map conditions) {
	return baseDao.queryByConditions(clazz, pageNo, pageSize, conditions);
    }

    public Page queryByConditions(Class clazz, Map conditions) {
	Page page = baseDao.queryByConditions(clazz, 1, Integer.MAX_VALUE,
	        conditions);
	if (page.getData() == null) {
	    page.setData(Collections.EMPTY_LIST);
	}

	return page;
    }

}
